<template>
  <div class="footer">
    <router-link v-for="(item, index) in list" :key="index" :to="item.link">
      <div
        class="item"
        @click="barClick(index)"
        :class="{ action: currentIndex == index }"
      >
        <img
          class="photo"
          :src="currentIndex == index ? item.imgs : item.img"
          alt=""
        />
        <div>{{ item.name }}</div>
      </div>
    </router-link>
  </div>
</template>
<script>
export default {
  name: "NavBar",

  props: {
    list: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  created() {
    this.chushi();
  },
  data() {
    return {
      currentIndex: 0
    };
  },
  methods: {
    chushi() {
      this.currentIndex = this.$store.state.index;
    },
    barClick(index) {
      this.currentIndex = index;
      this.$store.commit("setindex", index);
    }
  },
  watch: {
    currentIndex(newIndex, oldIndex) {
      // console.log(newIndex, oldIndex);
      this.currentIndex = newIndex;
    }
  }
};
</script>
<style scoped>
a {
  text-decoration: none;
  color: rgb(212, 212, 212);
}
.footer {
  position: fixed;
  width: 100%;
  height: 47px;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background-color: #333333;
  justify-content: space-around;
  align-items: center;
  z-index: 999;
  font-size: 10px;
  font-family: "Microsoft YaHei";
}

.action {
  color: #00aeff;
}
.item {
  font-size: 12px;
  height: 47px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  min-width: 80px;
}
.photo {
  margin-top: 5px;
  display: block;
  height: 23px;
  width: 23px;
}
</style>
